package com.wuxf.controller;

import java.util.Date;
import java.util.UUID;

import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSONObject;
import com.wuxf.entity.custom.UserInfoCustom;

@Controller
public class IndexController {
	
	
	@RequestMapping("/goToIndex")
	public String goToIndex(Model model,HttpSession session) {
		UserInfoCustom userInfoCustom = null;
		if(session.getAttribute("userInfoCustom") != null) {
			userInfoCustom = (UserInfoCustom)session.getAttribute("userInfoCustom");
		}
		if(userInfoCustom!=null) {
			model.addAttribute("userInfoCustom", JSONObject.toJSONString(userInfoCustom));
			model.addAttribute("userInfo", userInfoCustom);
			
			if(userInfoCustom.getRoleId().equals("2")){
				model.addAttribute("src","/dataAnalyze/goToindex");
			}else if(userInfoCustom.getRoleId().equals("4")){
				model.addAttribute("src","/pwd/goToDistribute");
			}else if(userInfoCustom.getRoleId().equals("5")){
				model.addAttribute("src","/gather/goToSubmit");
			}else{
				model.addAttribute("src","/finance/goToQuery");
			}
			return "index";
		}else {
			return "login";
		}
	}
	
	@RequestMapping("/getToken")
	public String goToToken(Model model,String key) {
		model.addAttribute("token", UUID.randomUUID().toString()+"-"+key);
		model.addAttribute("date", new Date());
		return "index";
	}
	
	@RequestMapping("/")
	public String goToLogin(Model model) {
		return "login";
	}
	
}
